LL_EXTI_Init and LL_EXTI_DeInit APIs migration

The LL initialization and de-initialization functions previously available in the stm32tnxx_ll_exti.c files within HAL1 are no longer present in HAL2. In HAL2, all LL C files ( stm32tnxx_ll_exti.c) have been removed, leaving only the LL header files ( stm32tnxx_ll_exti.h) that contain static inline functions.

If users need to initialize or de-initialize EXTI using the LL layer, they have two methods:

  • Utilize STM32CubeMX2 Code Generation: Rely on STM32CubeMX2 to generate code with the LL layer for EXTI initialization and de-initialization.

  • Replace manually the initialization and de-initialization functions : Replace the LL_EXTI_Init and LL_EXTI_DeInit functions manually with equivalent sequences using the static inline functions provided in the stm32tnxx_ll_exti.h file, tailored to their specific configuration and requirements.

This approach ensures that the initialization and de-initialization sequences are precisely addressing the given use case based on the LL static inline functions provided in the stm32tnxx_ll_exti.h header file. The sequences offer improved footprint optimization compared to the previous LL initialization functions found in stm32tnxx_ll_exti.c.

Related concept:

Method 1: Utilize STM32CubeMX2 Code Generation

LL GPIO configuration panel

Create a new project with the STM32CubeMX2, then start the initialization and the main configuration.

Project configuration panel

LL GPIO pin selection and EXTI configuration

Configure the GPIO settings, then enable EXTI to access the EXTI configuration.

STM32CubeMX2 EXTI Configuration

LL EXTI trigger configuration

The EXTI line should be selected.

EXTI pin selection

LL Generated EXTI initialization sequence

The EXTI initialization and de-initialization sequences are generated in the mx_gpio_default_init and mx_gpio_default_deinit functions in mx_gpio_default.c file under $YOUR_PROJECT_NAME$/$YOUR_PROJECT_NAME$_SW/generated/STM32Cube_CodeGen.

EXTI comparison between HAL1 and HAL2

HAL1

HAL2

Initialization and configuration sequence

static void MX_GPIO_Init(void)
{
    LL_EXTI_InitTypeDef EXTI_InitStruct = {0};

    /* GPIO Ports Clock Enable */
    LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC);










    /**/
    LL_EXTI_SetEXTISource(LL_EXTI_EXTI_PORTC, LL_EXTI_EXTI_LINE13);

    /**/
    EXTI_InitStruct.Line_0_31 = LL_EXTI_LINE_13;
    EXTI_InitStruct.LineCommand = ENABLE;
    EXTI_InitStruct.Mode = LL_EXTI_MODE_IT;
    EXTI_InitStruct.Trigger = LL_EXTI_TRIGGER_RISING;
    LL_EXTI_Init(&EXTI_InitStruct);

    /**/
    LL_GPIO_SetPinPull(GPIOC, LL_GPIO_PIN_13, LL_GPIO_PULL_NO);

    /**/
    LL_GPIO_SetPinMode(GPIOC, LL_GPIO_PIN_13, LL_GPIO_MODE_INPUT);

    /* EXTI interrupt init*/
    NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_3);
    NVIC_SetPriority(EXTI13_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 0, 0));
    NVIC_EnableIRQ(EXTI13_IRQn);
}
system_status_t mx_gpio_default_init(void)
{

    /* Enable peripherals and GPIO Clocks */
    /* GPIOC Clock activation */
    LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC);

    /* Activate the Pull-up, Pull-down resistor, or No pull for the current IO. */
    LL_GPIO_SetPinPull(GPIOC, LL_GPIO_PIN_13, LL_GPIO_PULL_NO);

    /* Configure IO Direction mode (Input, Output, Alternate or Analog) */
    LL_GPIO_SetPinMode(GPIOC, LL_GPIO_PIN_13, LL_GPIO_MODE_INPUT);

    LL_EXTI_EnableRisingTrig_0_31(1UL << 13);
    LL_EXTI_DisableFallingTrig_0_31(1UL << 13);

    /* Compute the EXTI source register and configure the corresponding GPIO port */
    LL_EXTI_SetEXTISource(LL_EXTI_GPIO_PORTC, LL_EXTI_GPIO_LINE13);














    /* Set line 13 Interrupt priority */
    NVIC_SetPriority(EXTI13_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 0, 0));
    NVIC_EnableIRQ(EXTI13_IRQn);

    return SYSTEM_OK;
}

Deinitialization sequence

void MX_GPIO_DeInit(void)
{
    LL_AHB2_GRP1_ForceReset(LL_AHB2_GRP1_PERIPH_GPIOA);
    LL_AHB2_GRP1_ReleaseReset(LL_AHB2_GRP1_PERIPH_GPIOA);
}
system_status_t mx_gpio_default_deinit(void)
{
    LL_EXTI_DisableIT_0_31(1UL << 13);
    LL_EXTI_DisableEvent_0_31(1UL << 13);
    LL_EXTI_DisableRisingTrig_0_31(1UL << 13);
    LL_EXTI_DisableFallingTrig_0_31(1UL << 13);
    LL_EXTI_ClearRisingFlag_0_31(1UL << 13);
    LL_EXTI_ClearFallingFlag_0_31(1UL << 13);

    /* Reset the EXTI source */
    LL_EXTI_SetEXTISource(LL_EXTI_GPIO_PORTC, LL_EXTI_GPIO_LINE13);

    /* Disable line 13 Interrupt */
    NVIC_DisableIRQ(EXTI13_IRQn);

    /* Configure IO in Analog Mode */
    LL_GPIO_SetPinMode(GPIOC, LL_GPIO_PIN_13, LL_GPIO_MODE_ANALOG);

    /* Configure the default Alternate Function in current IO */
    LL_GPIO_SetAFPin_8_15(GPIOC, LL_GPIO_PIN_13, LL_GPIO_AF_0);

    /* Configure the default value for IO Speed */
    LL_GPIO_SetPinSpeed(GPIOC, LL_GPIO_PIN_13, LL_GPIO_SPEED_FREQ_LOW);

    /* Configure the default value IO Output Type */
    LL_GPIO_SetPinOutputType(GPIOC, LL_GPIO_PIN_13, LL_GPIO_OUTPUT_PUSHPULL);

    /* Deactivate the Pull-up and Pull-down resistor for the current IO */
    LL_GPIO_SetPinPull(GPIOC, LL_GPIO_PIN_13, LL_GPIO_PULL_NO);

    LL_GPIO_ResetOutputPin(GPIOC, LL_GPIO_PIN_13);

    return SYSTEM_OK;
}

Method 2: Replace manually the initialization and de-initialization functions

LL_EXTI_Init() API migration

According to the use-case, implement the precise sequence call based on the LL static inline functions provided in the stm32tnxx_ll_exti.h header file.

EXTI comparison between HAL1 and HAL2

HAL1

HAL2

Case of EXTI mode IT and trigger rising

LL_EXTI_InitTypeDef   EXTI_InitStruct;

EXTI_InitStruct->Line_0_31      = LL_EXTI_LINE_1;
EXTI_InitStruct->LineCommand    = ENABLE;
EXTI_InitStruct->Mode           = LL_EXTI_MODE_IT;
EXTI_InitStruct->Trigger        = LL_EXTI_TRIGGER_FALLING;

LL_EXTI_Init(&EXTI_InitStruct);
LL_EXTI_DisableEvent_0_31(LL_EXTI_LINE_1);
LL_EXTI_EnableIT_0_31(LL_EXTI_LINE_1);
LL_EXTI_DisableFallingTrig_0_31(LL_EXTI_LINE_1);
LL_EXTI_EnableRisingTrig_0_31(LL_EXTI_LINE_1);

Case of EXTI mode IT and trigger rising falling

LL_EXTI_InitTypeDef   EXTI_InitStruct;

EXTI_InitStruct->Line_0_31      = LL_EXTI_LINE_1;
EXTI_InitStruct->LineCommand    = ENABLE;
EXTI_InitStruct->Mode           = LL_EXTI_MODE_IT;
EXTI_InitStruct->Trigger        = LL_EXTI_TRIGGER_RISING_FALLING;

LL_EXTI_Init(&EXTI_InitStruct);
LL_EXTI_DisableEvent_0_31(LL_EXTI_LINE_1);
LL_EXTI_EnableIT_0_31(LL_EXTI_LINE_1);
LL_EXTI_DisableRisingTrig_0_31(LL_EXTI_LINE_1);
LL_EXTI_EnableFallingTrig_0_31(LL_EXTI_LINE_1);

Case of EXTI mode IT and trigger rising falling

LL_EXTI_InitTypeDef   EXTI_InitStruct;

EXTI_InitStruct->Line_0_31      = LL_EXTI_LINE_1;
EXTI_InitStruct->LineCommand    = ENABLE;
EXTI_InitStruct->Mode           = LL_EXTI_MODE_IT;
EXTI_InitStruct->Trigger        = LL_EXTI_TRIGGER_RISING;

LL_EXTI_Init(&EXTI_InitStruct);
LL_EXTI_DisableEvent_0_31(LL_EXTI_LINE_1);
LL_EXTI_EnableIT_0_31(LL_EXTI_LINE_1);
LL_EXTI_EnableRisingTrig_0_31(LL_EXTI_LINE_1);
LL_EXTI_EnableFallingTrig_0_31(LL_EXTI_LINE_1);

Case of EXTI mode event and trigger rising

LL_EXTI_InitTypeDef   EXTI_InitStruct;

EXTI_InitStruct->Line_0_31      = LL_EXTI_LINE_1;
EXTI_InitStruct->LineCommand    = ENABLE;
EXTI_InitStruct->Mode           = LL_EXTI_MODE_EVENT;
EXTI_InitStruct->Trigger        = LL_EXTI_TRIGGER_RISING;

LL_EXTI_Init(&EXTI_InitStruct);
LL_EXTI_DisableIT_0_31(LL_EXTI_LINE_1);
LL_EXTI_EnableEvent_0_31(LL_EXTI_LINE_1);
LL_EXTI_DisableFallingTrig_0_31(LL_EXTI_LINE_1);
LL_EXTI_EnableRisingTrig_0_31(ELL_EXTI_LINE_1);

Case of EXTI mode event and trigger falling

LL_EXTI_InitTypeDef   EXTI_InitStruct;

EXTI_InitStruct->Line_0_31      = LL_EXTI_LINE_1;
EXTI_InitStruct->LineCommand    = ENABLE;
EXTI_InitStruct->Mode           = LL_EXTI_MODE_EVENT;
EXTI_InitStruct->Trigger        = LL_EXTI_TRIGGER_FALLING;

LL_EXTI_Init(&EXTI_InitStruct);
LL_EXTI_DisableIT_0_31(LL_EXTI_LINE_1);
LL_EXTI_EnableEvent_0_31(LL_EXTI_LINE_1);
LL_EXTI_DisableRisingTrig_0_31(LL_EXTI_LINE_1);
LL_EXTI_EnableFallingTrig_0_31(ELL_EXTI_LINE_1);

Case of EXTI mode event and trigger rising falling

LL_EXTI_InitTypeDef   EXTI_InitStruct;

EXTI_InitStruct->Line_0_31      = LL_EXTI_LINE_1;
EXTI_InitStruct->LineCommand    = ENABLE;
EXTI_InitStruct->Mode           = LL_EXTI_MODE_EVENT;
EXTI_InitStruct->Trigger        = LL_EXTI_TRIGGER_RISING_FALLING;

LL_EXTI_Init(&EXTI_InitStruct);
LL_EXTI_DisableIT_0_31(LL_EXTI_LINE_1);
LL_EXTI_EnableEvent_0_31(LL_EXTI_LINE_1);
LL_EXTI_EnableRisingTrig_0_31(LL_EXTI_LINE_1);
LL_EXTI_EnableFallingTrig_0_31(ELL_EXTI_LINE_1);

Case of EXTI mode IT event and trigger rising

LL_EXTI_InitTypeDef   EXTI_InitStruct;

EXTI_InitStruct->Line_0_31     = LL_EXTI_LINE_1;
EXTI_InitStruct->LineCommand    = ENABLE;
EXTI_InitStruct->Mode           = LL_EXTI_MODE_IT_EVENT;
EXTI_InitStruct->Trigger        = LL_EXTI_TRIGGER_RISING_FALLING;

LL_EXTI_Init(&EXTI_InitStruct);
LL_EXTI_EnableIT_0_31(LL_EXTI_LINE_1);
LL_EXTI_EnableEvent_0_31(LL_EXTI_LINE_1);
LL_EXTI_DisableFallingTrig_0_31(LL_EXTI_LINE_1);
LL_EXTI_EnableRisingTrig_0_31(LL_EXTI_LINE_1);

Case of EXTI mode IT event and trigger falling

LL_EXTI_InitTypeDef   EXTI_InitStruct;

EXTI_InitStruct->Line_0_31     = LL_EXTI_LINE_1;
EXTI_InitStruct->LineCommand    = ENABLE;
EXTI_InitStruct->Mode           = LL_EXTI_MODE_IT_EVENT;
EXTI_InitStruct->Trigger        = LL_EXTI_TRIGGER_RISING_FALLING;

LL_EXTI_Init(&EXTI_InitStruct);
LL_EXTI_EnableIT_0_31(LL_EXTI_LINE_1);
LL_EXTI_EnableEvent_0_31(LL_EXTI_LINE_1);
LL_EXTI_DisableRisingTrig_0_31(LL_EXTI_LINE_1);
LL_EXTI_EnableFallingTrig_0_31(LL_EXTI_LINE_1);

Case of EXTI mode IT event and trigger rising falling

LL_EXTI_InitTypeDef   EXTI_InitStruct;

EXTI_InitStruct->Line_0_31     = LL_EXTI_LINE_1;
EXTI_InitStruct->LineCommand    = ENABLE;
EXTI_InitStruct->Mode           = LL_EXTI_MODE_IT_EVENT;
EXTI_InitStruct->Trigger        = LL_EXTI_TRIGGER_RISING_FALLING;

LL_EXTI_Init(&EXTI_InitStruct);
LL_EXTI_EnableIT_0_31(LL_EXTI_LINE_1);
LL_EXTI_EnableEvent_0_31(LL_EXTI_LINE_1);
LL_EXTI_EnableRisingTrig_0_31(LL_EXTI_LINE_1);
LL_EXTI_EnableFallingTrig_0_31(LL_EXTI_LINE_1);

LL_EXTI_DeInit() API migration

Comparison of HAL1 and HAL2

HAL1

HAL2

LL_EXTI_DeInit(void);
/* Adapt the following list of register  writes and values according to the given
series to deinitialize the EXTI lines as  per the reference manual sequence. */

LL_EXTI_WRITE_REG(IMR1,   0xFFFE0000U);
...
LL_EXTI_WRITE_REG(EMR1,   0x00000000U);
...
LL_EXTI_WRITE_REG(RTSR1,  0x00000000U);
...
LL_EXTI_WRITE_REG(SWIER1, 0x00000000U);
...
LL_EXTI_WRITE_REG(RPR1,   0xFFFFFFFFU);
...
LL_EXTI_WRITE_REG(RPR2,   0xFFFFFFFFU);
...
LL_EXTI_WRITE_REG(PRIVCFGR1,  0x00000000U);
...
LL_EXTI_WRITE_REG(SECCFGR1,  0x00000000U);
...